Page({

  data: {
    song: [],
    musics: [],
    picUrl: ""
  },

  async onSubmit(event) {
    console.log(event.detail.value);
    var keyword = event.detail.value.name
    var url = `http://47.108.197.28:3000/search?keywords=${keyword}`
    wx.request({
      url,
      data: {},
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {
        var songs = res.data.result.songs;
        var musics = []
        songs.forEach(item => {
          var { id, name, artists } = item;
          musics.push({
            name,
            id,
            author: artists[0].name,
          })
        })
        this.setData({
          musics
        })
        var id = musics.map(item => {
          return item.id
        })
        console.log(id);
        var url = `http://47.108.197.28:3000/song/detail?ids= ${id}`
        wx.request({
          url,
          data: {},
          header: { 'content-type': 'application/json' },
          method: 'GET',
          dataType: 'json',
          responseType: 'text',
          success: (res) => {
            var songs = res.data.songs;
            var music = []
            songs.forEach(item => {
              var picUrl = item.al.picUrl;
              music.push(picUrl)
            })
            this.setData({
              music
            })
          },

        });
      },


    });


  },


})